package com.bookcloud.java21.chapter11.集合元素遍历foreach117;

import java.util.*;

/** 集合元素遍历foreach117 */
public class ForEachExamples {
  public static void main(String[] args) {
    // 一、迭代列表类
    List<String> list = Arrays.asList("A", "B", "C");
    for (String element : list) {
      System.out.println("迭代列表类->元素：" + element);
    }
    System.out.println("===========================");
    // 二、迭代数组类
    String[] array = {"A", "B", "C"};
    for (String element : array) {
      System.out.println("迭代数组类->元素：" + element);
    }
    System.out.println("===========================");
    // 三、迭代集合类 set
    Set<String> set = Set.of("A", "B", "C");
    for (String element11 : set) {
      System.out.println("迭代集合类->元素：" + element11);
    }
    System.out.println("===========================");
    // 四、迭代Map
    Map<String, Object> map = new HashMap<>();
    map.put("name", "张三");
    map.put("age", 18);
    map.put("sex", "男");
    for (Map.Entry<String, Object> entry : map.entrySet()) {
      System.out.println("迭代Map->键：" + entry.getKey() + "，值：" + entry.getValue());
    }
  }
}
